/*
 * QTeXPreview
 * Copyright (C) 2008, Philip Pronin (philip.pronin@gmail.com)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef TEX_H
#define TEX_H

#include <QObject>
#include <QProcess>

class TeXFrontEnd: public QObject {
	Q_OBJECT

public:
	TeXFrontEnd(QObject* parent = NULL) : QObject(parent) {}
	virtual bool render(const QString& eq) = 0;
	virtual QByteArray renderNow(const QString& eq) const = 0;

	virtual QString getRenderFormat() const = 0;
	virtual QString getRenderFormatFilter() const = 0;

	static TeXFrontEnd* create(QObject* parent = NULL);

signals:
	virtual void rendered(QByteArray data);
};

class MimeTeX: public TeXFrontEnd {
	Q_OBJECT

public:
	MimeTeX(QObject* parent = NULL);
	virtual ~MimeTeX();

	virtual bool render(const QString& eq);
	virtual QByteArray renderNow(const QString& eq) const;

	virtual QString getRenderFormat() const;
	virtual QString getRenderFormatFilter() const;

signals:
	virtual void renderStarted();
	virtual void renderFinished(QByteArray data);

private:
	void start();

private slots:
	void finished(int exitCode, QProcess::ExitStatus exitStatus);

private:
	static const QString mimetexFilename;
	QString equation;
	bool queued;
	QProcess* process;
};

#endif /* TEX_H */
